/*******************    (C) COPYRIGHT SUNSHINE SILICON    **********************
* \file
* File Name: hw_spi.c
* \brief
* Description:

    Hardware spi
    
*  Copyright (C) 2014-2035 Sunshine Silicon Corporation (www.sunsili.com), All Rights Reserved
*  SPDX-License-Identifier: Apache-2.0
*
*  Licensed under the Apache License, Version 2.0 (the "License"); you may
*  not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
*  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*
*  This file is part of HS6200 SDK
*
* Version && Reversed History
* Version    Date       Auther      Reversed History
  ----------------------------------------------------------------------------
  V1.0.0    2021-07-07  Lojam Fan  Fisrt Created 
  
(C) Sunshine Silicon Corporation (http://www.sunsili.com)
*******************************************************************************/

#include "hw_spi.h"

unsigned char SPI_Flag;


/*******************************************************************************
* Function: hw_spi_init
* Return:   void
* Param:    void
* Description::
    --
* Version    Date       Auther      Reversed History
  ---------------------------------------------------------------------------
  V1.0.0    2021-10-20  Lojam Fan  First Created 

* FILE: hw_spi.c

*******************************************************************************/
void hw_spi_init ( void )
{
#ifdef MCU_STC12C5A60
    SPCTL = (SSIG << 7) + (SPEN << 6) + (DORD << 5) + (MSTR << 4) + (CPOL << 3) + (CPHA << 2) + SPEED_16;
#endif

}

/*******************************************************************************
* Function: hw_spi_rw
* Return:   unsigned char
* Param:    unsigned char dat
* Description::
    --
* Version    Date       Auther      Reversed History
  ---------------------------------------------------------------------------
  V1.0.0    2021-10-20  Lojam Fan  First Created 

* FILE: hw_spi.c

*******************************************************************************/
unsigned char hw_spi_rw ( unsigned char dat )
{
    unsigned char ret;		
	SPI_Flag = SPI_FLG_BUSY;
	SPI0DAT = dat; 
	while(SPI_Flag==SPI_FLG_BUSY);  
	ret=SPI0DAT;
	return ret;
}




/******************* (C) COPYRIGHT SUNSHINE SILICON  **************************
********************        END OF FILE hw_spi.c        *******************/

